#include <vector>
#include "events.h"

class ComponentBase;

class Entity
{
public:
    Events onAddToScene;
    Events onRemoveFromScene;
    Events onDie;
    Events onRelive;

    template<typename T>
    T* getComponent()
    {
        for(auto i : components)
        {
            if(i->test_class<T>())
            {
                return (T*)i;
            }
        }
        return nullptr;
    }

    void add(ComponentBase *comp)
    {
        components.push_back(comp);
    }

    void remove(ComponentBase *comp)
    {
        for(auto it = components.begin(); it != components.end();)
        {
            if(*it == comp)
            {
                it = components.erase(it);
            }
            else
            {
                ++it;
            }
        }
    }

private:
    std::vector<ComponentBase*> components;//不是用来遍历的
};

